﻿using System.Collections.Generic;
using System.Linq;

namespace Liphofra.Mvvm.Validation
{
    /// <summary>
    /// Encapsulates a collection of validation results.
    /// </summary>
    public class ValidationResults
    {
        private static readonly ValidationResults _success = new ValidationResults(null);

        /// <summary>
        /// Gets the static validation results instance that indicates successful validation.
        /// </summary>
        public static ValidationResults Success
        {
            get
            {
                return _success;
            }
        }

        /// <summary>
        /// Gets the collection of validation results that represent the errors.
        /// </summary>
        public IEnumerable<ValidationResult> Errors
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets a value indicating whether this validation results container contains any errors.
        /// </summary>
        /// <value>
        /// <c>true</c> if this validation results container has errors; otherwise, <c>false</c>.
        /// </value>
        public bool HasErrors
        {
            get
            {
                return Errors != null && Errors.Any();
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationResults"/> class.
        /// </summary>
        /// <param name="errors">The errors to encapsulate.</param>
        public ValidationResults(IEnumerable<ValidationResult> errors)
        {
            Errors = errors;
        }
    }
}